<template>
	<view class="content" >
		<u-navbar :is-back="false" :border-bottom="false" height="80rpx">
			<view style="padding-left: 10px;width: 15%;">商机</view>
			<view  class="slot-wrap disfr-lr p15 f32" style="width: 90%;">
				<!--<view class="slot-wrap-left"></view>-->
				<!--<view class="slot-wrap-center mt20"></view>-->
				<view class="slot-wrap-right pr disf" style="width:100%">
					<view  style="position: relative;top:-2px;right: -3px;width: 75%;">
						<u-search v-model="keyword" @search="toSearch" shape="round" @clear="clearContent" :clearabled="true" :show-action="false" :animation="true"></u-search>
					</view>
					<view style="margin-left: 20px;position: relative;top:2px;right:0px;"
					@click="goPage" data-uri="/pages/business-create/business-create">
						<u-icon name="plus-circle" custom-prefix="qxl-icon" size="40" style="position: relative;top:1px;"></u-icon>发布
					</view>
				</view>
			</view>
		</u-navbar>
		<!--<my_navbar_ext height="90" bg-color="#ffffff">
			<scroll-view
			:style="{width:'100%'}"
			scroll-x="true" 
			:show-scrollbar="false"
			:scroll-with-animation="true">
				<view class="f28 pt20 pb20 disf" style="width: 100%;">
					<view v-for="(item,index) in classify" :key="index" 
					class="mr20" @click="getClasspage" :data-id="item.id"
					style="text-align: center;width: 120rpx;flex-shrink: 0;">
						<view><image :src="item.icon_pic" style="width: 80rpx;height:80rpx;border-radius:6px;flex-shrink: 0;"></image></view>
						<view class="toell">{{item.name}}</view>
					</view>
				</view>
			</scroll-view>
		</my_navbar_ext>-->
		
		<view class="disf ph20" style="flex-wrap: wrap;padding-top: 180rpx;padding-bommon: 10rpx;">
			<view v-for="(item,index) in banner" :key="item.id" @click="goPage" :data-uri="item.outside_url" class="banner-ads mr5 mt5">
				<image :src="item.thumb1" style="width: 100%;height: 100%;"></image>
			</view>
		</view>
		<view class="cate-list ph30">
			<scroll-view
			:style="{width:'100%'}"
			scroll-x="true" 
			:show-scrollbar="false"
			:scroll-with-animation="true">
				<view class="f28 pt20 pb20 disf" style="width: 100%;">
					<view v-for="(item,index) in classify" :key="index" 
					class="mr20" @click="getClasspage" :data-id="item.id"
					style="text-align: center;width: 120rpx;flex-shrink: 0;">
						<view><image :src="item.icon_pic" style="width: 80rpx;height:80rpx;border-radius:6px;flex-shrink: 0;"></image></view>
						<view class="toell">{{item.name}}</view>
					</view>
				</view>
			</scroll-view>
		</view>
		
		
	    <view style="height: 10px;"></view>		
		<!--<view class="banner">
			<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
			:duration="duration" :indicator-color='indicatorColor'>
			   <swiper-item v-for="(item,index) in banner" >
			   		<view @click="goPage" :data-uri="item.outside_url">
						<image :src="item.thumb1" style="width: 100%;height: 287rpx;" ></image>
					</view>
			   </swiper-item>
			</swiper>
		</view>	-->
			
		<view v-if="show_main" class="main" >
			<view class="disfr-lr f30 mt30 mb10 ph30">
				<view class="disf">区域
					<!--<view @click="orderField('order_field','coin_orders')" class="mr30" :style="orderActivity == 'coin_orders' ? 'color:#2979ff' : ''">精选</view>
					<view @click="orderField('order_field','add_time')" :style="orderActivity == 'add_time' ? 'color:#2979ff' : ''">最新</view>-->
				</view>
				<view @click="goPage" data-uri="/pages/city-index/city-index">
					{{$vuex.state.globalData.businessCity.name ? $vuex.state.globalData.businessCity.name : '全国'}}<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			
			<view v-for="(item,index) in list" :key="index" @click="goPage" :data-uri="'/pages/business-details/business-details?id='+item.id" class="bgf m20 pr f30 p20" style="border-radius: 4px;">
				
				<view v-if="item.coin_orders > 0 || item.orders > 0" class="pa" style="right: 0;top:0;">
					<u-icon name="zhiding" custom-prefix="qxl-icon" color="#2979ff" size="70"></u-icon>
				</view>
				<view class="f30 b mb10">{{item.title}}</view>
				<view class="list disfr-lr">
					<!--<view class="disf" style="width: 300rpx;">
						<view style="width: 46rpx;height: 46rpx;overflow: hidden;border-radius:4px;flex-shrink: 0;">
							<u-image width="48rpx" height="48rpx" :src="item.head_pic">
								<template v-slot:error>
									<image src="/static/image/default-user.png" style="width:48rpx;height: 48rpx;"></image>
								</template>
							</u-image>
						</view>
						<view class="ml10 toell pr" style="top:3rpx;">{{item.nickname}}</view>
					</view>-->
					<view class="col999">{{item.add_time_str}}</view>
				</view>
				
				<view class="p20 mt20" style="background: #f4f4f4;border-radius: 6px;min-height: 100rpx;">
					{{item.content}}
				</view>
				<view class="disfr-lr mt10 col999">
					<view class="mt5" style="color:#2979ff">{{item.classify_name}}</view>
					<view class="disf">
						<view class="pr" style="top:8rpx;right: 30rpx;">{{item.area}}</view>
						<view>
							<u-icon name="eye-fill" size="44" style="position: relative;top:5rpx;"></u-icon>{{item.page_view}}
						</view>
					</view>
				</view>
			</view>
			
            <view v-if="list.length <= 0 && not_load" style="text-align: center;margin-top: 40%;">
				<view><u-icon name="wuneirong-copy" custom-prefix="qxl-icon" color="#999999" size="100"></u-icon></view>
				<view class="f32 col999 mt20">什么都木有哦</view>
			</view>
			
		</view>
		
		<pageload :page_load="page_load" :next_page="next_page" :list="list" /><!--分页加载状态-->
		<view style="height: 50px;"></view>
	   <!--<loading :loading="not_load"/><!--加载状态-->
	   <u-tabbar v-model="$vuex.state.globalData.tabBar.current" height="105rpx" icon-size="40rpx"
	   :list="$vuex.state.globalData.tabBar.list" active-color="#2979ff" 
	   :mid-button="false"></u-tabbar><!--自定义底部导航-->
	   <u-no-network tips="哎呀，网络信号丢失"></u-no-network><!--检测网络-->
	</view>
</template>

<script setup>
import { onLoad, onShow, onHide, onReachBottom,onPullDownRefresh } from '@dcloudio/uni-app';
import { ref } from 'vue';	
const show_main=ref(false);
const page_load=ref(false);
const not_load=ref(false);
const next_page=ref('');
const keyword=ref('');
const search=ref(false);
const list=ref([]);
const classify=ref([]);
const searchParam=ref({});
const banner=ref([]);
// banner图
const indicatorDots=ref(true); // 是否显示面板指示点
const indicatorColor=ref('#2979ff'); // 面板指示点颜色
const autoplay=ref(true); // 自动播放
const interval=ref(5000); // 切换时间
const duration=ref(500);// 滑动动画时长
//页面加载时
onLoad(async (options)=>{
	getclassify();
	uni.offNetworkStatusChange(connected)
    uni.onNetworkStatusChange(connected);
});
const connected=(res)=>{
	if(res.isConnected){
		getclassify();
		loadPage(searchParam.value,false);
	}
};
//页面显示时执行
onShow(()=>{
	//console.log('语法糖onShow');
	let city=uni.$vuex.state.globalData.businessCity.name;
	city=city ? city : '';
	searchParam.value.area=city;
	loadPage(searchParam.value,false);
	
});
//页面隐藏时执行
onHide(()=>{
	
});
//获取群分类
const getclassify=async()=>{
	let ret = await uni.$get('/appapi-opportunity-getcategory',{page_zise:100});
	classify.value=ret.data;
};
// 获取分类ID群聊列表
const getClasspage=async(e)=>{
	let c_id=e.currentTarget.dataset.id;
	searchParam.value.classify_id=c_id;
	loadPage(searchParam.value,false);
};
/**
 * 加载接口数据
 * @param {Object} options  参数,对像数组
 * @param {Object} isPage   是否加载大于1页
 */
const loadPage=async (options,isPage)=>{
	
	not_load.value=false;
	let ret = await uni.$get('/appapi-opportunity-getlist',options);
	//console.log(ret);
	if(ret.error_code != 0){
		uni.$utils.showToast(ret.info);
		return;
	}
    page_load.value=false;
	show_main.value=true;
	not_load.value=true;
	next_page.value=ret.data.next_page;
	let tempString='';
	for(let i in ret.data.list){
		tempString=ret.data.list[i].content;
		tempString=tempString.replace(/\\n\\r/g,'');
		ret.data.list[i].content=uni.$utils.substr(tempString,52,'');
	}
	if(isPage) list.value=[...list.value,...ret.data.list];
	else list.value=ret.data.list;
	banner.value=ret.data.banner;
};
onPullDownRefresh(()=>{
	//console.log('onPullDownRefresh');
	//not_load.value=false;
	setTimeout(()=>{
		loadPage({},false);
		uni.stopPullDownRefresh();
	}, 1000);
});
//上拉触底加载分页
onReachBottom(()=>{
	if (!next_page.value) return;
	if (page_load.value) return;
	page_load.value=true;
	setTimeout(()=>{
	  loadPage(next_page.value, true); 
	},2000);
});
/**
 * 模板属性跳转页面
 * @param {Object} e
 */
function goPage(event){
	if(!event.currentTarget.dataset.uri) return;
	if((event.currentTarget.dataset.uri).indexOf('://') > -1){
		plus.runtime.openURL(event.currentTarget.dataset.uri);
		return;
	}
	//topDropDownShow.value=false;
	//console.log(111111);
	uni.$utils.dataSetPage(event);
};
//清空关键字
const clearContent=()=>{
	keyword.value='';
};
// 显示检索
const showSearch=()=>{
	search.value=true;
};
//去检索
const toSearch=()=>{
	searchParam.value.keywords=keyword.value;
	loadPage(searchParam.value,false);
};
//精选检索
const orderActivity=ref('');
const orderField=(field,value)=>{
	searchParam.value[field]=value;
	orderActivity.value=value;
	loadPage(searchParam.value,false);
};
</script>

<style  lang="scss">
	page {
		
	}
.fnow{color:#2979ff;}
.banner{width: 700rpx;margin: 0 auto;border-radius: 10px;overflow: hidden;}
.banner-ads{flex-shrink: 0;width: 231rpx;height: 130rpx;}
.banner-ads image{border-radius: 2px;}
</style>
